package suanfa;

public class SingleLinkedList
{
    //定义一个头节点
    private HeroNode head = new HeroNode(0, "", "");

    //添加节点到单项链表
    //1、找到当前链表的最后节点
    //2、将最后这个节点的next指向新的节点
    public void add(HeroNode heroNode)
    {
        //因为head节点不能动，因此我们需要一个辅助遍历temp
        HeroNode temp = head;
        //遍历链表，找到最后
        while (true)
        {
            //找到链表的最后
            if (temp.next == null)
            {
                break;
            }
            temp = temp.next;
        }
        temp.next = heroNode;
    }

}

//自己定义的节点
class HeroNode
{
    public int no;
    public String name;
    public String nickname;
    public HeroNode next;

    //构造器
    public HeroNode(int no, String name, String nickname)
    {
        this.no = no;
        this.name = name;
        this.nickname = nickname;
    }

    //重新定义toString
    @Override
    public String toString()
    {
        return "HeroNode [no=" + no + ",name=" + name + ",nickname" + nickname + "]";
    }
}